Conditions | 1 |
Paths | 1 |
Total Lines | 65 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | 'use strict'; |
||
10 | describe(`${pkg.name}/Botlang`, () => { |
||
11 | /** @test {Botlang#constructor} */ |
||
12 | describe('#constructor', () => { |
||
13 | it('Create a new instance of type Botlang', () => { |
||
14 | const sourceCode = fs.readFileSync(path.join(__dirname, 'Data', 'hello_world.bot'), { |
||
15 | encoding : 'utf8', |
||
16 | flag : 'r' |
||
17 | }), |
||
18 | botlang = new Botlang(sourceCode); |
||
19 | |||
20 | assert.instanceOf(botlang, Botlang); |
||
21 | }); |
||
22 | }); |
||
23 | |||
24 | /** @test {Botlang#reply} */ |
||
25 | describe('#reply', () => { |
||
26 | const sourceCode = fs.readFileSync(path.join(__dirname, 'Data', 'hello_world.bot'), { |
||
27 | encoding : 'utf8', |
||
28 | flag : 'r' |
||
29 | }), |
||
30 | botlang = new Botlang(sourceCode); |
||
31 | |||
32 | it('Should return an empty string', () => { |
||
33 | assert.match(botlang.reply(''), /^$/); |
||
34 | }); |
||
35 | |||
36 | it('Should return "Hi, how is it going?"', () => { |
||
37 | assert.match(botlang.reply('Hey'), /Hi, how is it going?/); |
||
38 | }); |
||
39 | |||
40 | it('Should return "I think Botlang is freakin awesome!"', () => { |
||
41 | assert.match( |
||
42 | botlang.reply('What do you think about Botlang?'), |
||
43 | /(I think Botlang is freakin awesome!|I think Botlang is great!|I think Botlang is the coolest thing on Earth!)/ |
||
44 | ); |
||
45 | }); |
||
46 | |||
47 | it('Should return "Hi, how are you?" or "Hey, how are you?"', () => { |
||
48 | assert.match(botlang.reply('Hello there'), /Hi, how are you?|Hey, how are you?/); |
||
49 | }); |
||
50 | |||
51 | it('Should return "Sorry, I do not know the answer to that question."', () => { |
||
52 | assert.match(botlang.reply('Yay ...'), /Sorry, I do not know the answer to that question./); |
||
53 | }); |
||
54 | |||
55 | it('Should return "I love you too"', () => { |
||
56 | assert.match(botlang.reply('I love you'), /I love you too./); |
||
57 | }); |
||
58 | |||
59 | it('Should return "Can you think of why you might forget names?"', () => { |
||
60 | assert.match(botlang.reply('Sometimes I forget names'), /Can you think of why you might forget names?/); |
||
61 | }); |
||
62 | |||
63 | it('Should return "Im you too"', () => { |
||
64 | assert.match(botlang.reply('I am good'), /Glad to hear that you are good./); |
||
65 | }); |
||
66 | }); |
||
67 | |||
68 | /** @test {Botlang#version} */ |
||
69 | describe('#version', () => { |
||
70 | it('Should return the current version', () => { |
||
71 | assert.equal(Botlang.version(), pkg.version); |
||
72 | }); |
||
73 | }); |
||
74 | }); |
||
75 |